import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home.vue'
import My from '../views/My.vue'
import Category from '../views/Category.vue'
import FoodDetails from '../views/Fooddetails.vue'
import Collect from '../views/Collect.vue'
import Edit from '../views/Edit.vue'
import Login from '../views/Login.vue'
import Search from '../views/Search.vue'
import Register from '../views/Register.vue'
import Addfood from '../views/Addfood.vue'
import Release from '../views/Release.vue'
import Language from '../views/Language.vue'
import Recipedisplay from '../views/Recipedisplay.vue'
Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'Home',
    component: Home,
    meta: {
      showTab: true

    },
    props: true,
  },
  //我的
  {
    path: '/my',
    name: 'My',
    component: My,
    meta: {
      showTab: true,
      requireAuth: true

    },

  },
  //美食分类
  {
    path: '/category',
    name: 'Category',
    component: Category,
    meta: {
      showTab: true,

    },
    props: true, // 启用参数传递
  },
  //美食详情页
  {
    path: '/fooddetails/:id',
    name: 'FoodDetails',
    component: FoodDetails,
    meta: {
      showTab: false

    },
  },
  //用户收藏
  {
    path: '/collect',
    name: 'collect',
    component: Collect,
    meta: {
      showTab: false,
      requireAuth: true

    },
  },
  //用户编辑
  {
    path: '/edit/:id',
    name: 'edit',
    component: Edit,
    meta: {
      showTab: false,
      requireAuth: true

    },
  },
  //登入
  {
    path: '/login',
    name: 'login',
    component: Login,
    meta: {
      showTab: false

    },
  },
  //注册
  {
    path: '/register',
    name: 'register',
    component: Register,
    meta: {
      showTab: false

    },
  },
  //搜索
  {
    path: '/search',
    name: 'search',
    component: Search,
    meta: {
      showTab: false

    },
  },
  //增加美食
  {
    path: '/addfood/:id',
    name: 'addfood',
    component: Addfood,
    meta: {
      showTab: false,
      requireAuth: true

    },
  },
  //我的发布
  {
    path: '/release',
    name: 'release',
    component: Release,
    meta: {
      showTab: false,
      requireAuth: true
    },
  },
  //自动生成
  {
    path: '/language',
    name: 'language',
    component: Language,
    meta: {
      showTab: false
    },
  },
  //自动生成展示页
  {
    path: '/recipedisplay',
    name: 'recipedisplay',
    component: Recipedisplay,
    meta: {
      showTab: false,
      requireAuth: true
    },
  }
]

const router = new VueRouter({
  routes,
  //解决每次点击新页面页面不置顶的bug
  scrollBehavior(to, from, savedPosition) {
    if (savedPosition) {
      return savedPosition
    } else {
      return { x: 0, y: 0 }
    }
  }
})


export default router
